package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.RadioGroup;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.fragment.ClassListFragment;
import com.banshuibao.bsb_android.fragment.MediaListFragment;

/**
 * Created by zyh on 2017/12/21.
 */

public class MediaListActivity extends BaseActivity {

    private FragmentManager manager;

    //private RadioGroup radioGroup;

    private MediaListFragment mediaListFragment;

    // private ClassListFragment classListFragment;

    //private int type;
    private String tag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_media_list);
        tag = getIntent().getStringExtra("tag");
        initView();
    }

    private void initView() {
        setTitleText("财税课堂");
//        ImageView share = findViewById(R.id.share);
//        share.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                ShareUtil.showShare(MediaListActivity.this, Constants.Url.VIDEO, "","", null);
//            }
//        });

//        ImageView record = findViewById(R.id.record);
//        record.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                IntentManager.goBuyMediaListActivity(context);
//            }
//        });
        //radioGroup = findViewById(R.id.rg);

        manager = getSupportFragmentManager();

       /* radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == type)
                    return;
                hideFragment(mediaListFragment, classListFragment);
                FragmentTransaction transaction = manager.beginTransaction();
                switch (i) {
                    case R.id.title1:
                        if (mediaListFragment == null) {
                            mediaListFragment = new MediaListFragment();
                            transaction.add(R.id.fragment, mediaListFragment);
                        } else
                            transaction.show(mediaListFragment);
                        break;
                    case R.id.title2:
                        if (classListFragment == null) {
                            classListFragment = new ClassListFragment();
                            transaction.add(R.id.fragment, classListFragment);
                        } else
                            transaction.show(classListFragment);
                        break;
                }
                transaction.commit();
                type = i;
            }
        });
        if (tag.equals("helping")) {
            radioGroup.check(R.id.title2);
        } else {
            radioGroup.check(R.id.title1);
        }*/
        FragmentTransaction transaction = manager.beginTransaction();
        mediaListFragment = new MediaListFragment();
        transaction.add(R.id.fragment, mediaListFragment).commit();
    }

    private void hideFragment(Fragment... fragments) {
        for (Fragment fragment : fragments) {
            if (fragment != null)
                manager.beginTransaction().hide(fragment).commit();
        }
    }
}
